#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 1e6 + 7;
int x, n, k, a[16];
int main() {
    scanf("%d%d", &n, &k);
    k = min(n, k);
    rep(i, 1, k) scanf("%d", &a[i]);
    sort(a + 1, a + k + 1);
    rep(i, k + 1, n) {
        scanf("%d", &x);
        if (x > a[1]) {
            a[1] = x;
            sort(a + 1, a + k + 1);
        }
    }
    sort(a + 1, a + k + 1, greater<int>());
    rep(i, 1, k) printf("%d%c", a[i], i == k ? '\n' : ' ');
}